package com.java.com.syun.bio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BIOThreadPoolServer {
    public static void main(String[] args) throws Exception {
        //创建线程池
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        ServerSocket server = null;
        try {
            server = new ServerSocket();
            server.bind(new InetSocketAddress(9000));
            while (true) {
                //客户端每一个socket创建一个线程
                Socket socket = server.accept();
                // 启动请求处理线程
                threadPool.submit(new syun.nacos.dubbo.service.HandleTask(socket));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            server.close();
        }
    }
}
